
public class P41_1 {
	public static boolean isPrime(long n) {
		if (n == 1) {
			return false;
		}
		
		long max = (long) Math.sqrt(n);
		for (long i = 2; i <= max; i++) {
			if (n%i == 0) {
				return false;
			}
		}
		
		return true;
	}
	
	public static void main(String[] args) {
		long max = 0;
		for (long i = 2; i <= 987654321; i++) {
			if (isPrime(i)) {
				String num = String.valueOf(i);
				int length = num.length();
				
				boolean isPandigital = true;
				for (int j = 1; j <= length; j++) {
					if (!num.contains(String.valueOf(j))) {
						isPandigital = false;
						break;
					}
				}
				
				if (isPandigital) {
					System.out.println(">>>" + i);
					if (max < i) {
						max = i;
					}
				}
			}
		}
		System.out.println(max);
	}
}
